import React from 'react';
import styles from './index.less';
import {useModel} from 'umi';
import { useState } from 'react';
import { history } from 'umi';

export default () => {
  let [mobile, setMobile] = useState('15323807318');
  let [password, setPassword] = useState('123456');

  let {isLogin, doLogin} = useModel('user', model=>({isLogin: model.isLogin, doLogin: model.doLogin}));

  async function loginClick(){
      //手机号正则
    if (!/^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013-8])|(18[0,5-9]))\d{8}$/.test(mobile)){
      alert('请输入正确的手机号');
      return;
    }
    //密码正则
    if (!password){
      alert('请输入正确的密码');
      return;
    }
    //调接口
    let result = await doLogin({mobile, password});
   //跳转首页
   history.push('/main/home');
  }


  return (
    <div className={styles.Logintitle}>
        <h1 >八维严选</h1>
        <div className={styles.Loginbox}>
            <input type="text" value={mobile} onChange={(e) => setMobile(e.target.value)} placeholder='请输入你的手机号' name="" id="" />
            <input type="password" value={password} onChange={(e) => setPassword(e.target.value)} placeholder='请输入你的密码' name="" id="" />
            <button onClick={loginClick}>登录</button>
        </div>

    </div>
);
}
